package com.sumainfor.wx.system.maket.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.sumainfor.common.Constants;
import com.sumainfor.common.entity.TemplateData;
import com.sumainfor.common.util.*;
import com.sumainfor.common.utlis.*;
import com.sumainfor.common.wechat.WeChatConfig;
import com.sumainfor.wx.system.feign.BaseFeignMarket;
import com.sumainfor.wx.system.feign.ZuulFeign.ZuulFeign;
import com.sumainfor.wx.system.maket.dao.RdPactMapper;
import com.sumainfor.wx.system.maket.dao.UtilsMapper;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.awt.*;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 * 签约
 * <p>
 *
 * @author: zc
 * @create: 2019-08-16 11:27
 **/

@Service
public class RdPactService {


    private ReentrantLock lock = new ReentrantLock(false);

    Logger log = LoggerFactory.getLogger(RdPactService.class);// 日志

    @Autowired
    RdPactMapper rdPactMapper;


    @Autowired
    UtilsMapper utilsMapper;

    @Autowired
    BaseFeignMarket baseFeignMarket;

    String UUID=null;

    /**
     * 已签约
     * @author zhoucong
     * @data 2019/8/16
     * @Param
     * @return
     */
    public List<Map<String,Object>> getPactListById(Map<String,Object> params){

        List<Map<String,Object>> getPactListByIdList = rdPactMapper.getPactListById(params);
        if (getPactListByIdList.size()>0){
            for (Map<String,Object> zczsMap:getPactListByIdList) {

                Double monthDiff = Double.valueOf(Integer.valueOf(DateUtils.getMonthSpace(MapUtils.getString(zczsMap,"StartTime"),MapUtils.getString(zczsMap,"EndTime"),"yyyy-MM-dd")).toString());
              zczsMap.put("monthDiff",monthDiff);
                zczsMap.put("PactPrice",CompuUtils.add(CompuUtils.mul(MapUtils.getDouble(zczsMap,"PaActMonthPrice"),monthDiff),CompuUtils.add(MapUtils.getDouble(zczsMap,"actualDeposit"),MapUtils.getDouble(zczsMap,"WaDeposit"))));
            }
        }

        return getPactListByIdList;
    }

    /**
     * 已签约数量
     * @author zhoucong
     * @data 2019/8/16
     * @Param
     * @return
     */
    public Integer getPactListCountById(Map<String,Object> params){
        return rdPactMapper.getPactListCountById(params);
    }


    /**
     * 发起签约时查看客户已签约的合同
     * @author zhoucong
     * @data 2019/8/19
     * @Param
     * @return
     */
    public List<Map<String,Object>> getPactListByTenId(Map<String,Object> params){
        return rdPactMapper.getPactListByTenId(params);
    }



}
